#include <functional>
#include <iostream>

using namespace std;

int bind1()
{
	std::function<int(int)> plus10 = std::bind(std::plus<int>(),
		std::placeholders::_1,
		10);
	cout << "+10:	" << plus10(7) << endl;		//17

	// expressions are evaluated from the inside to the outside.
	auto plus10times2 = std::bind(std::multiplies<int>(),
		std::bind(std::plus<int>(), std::placeholders::_1, 10),
		2);
	cout << "+10 *2:	" << plus10times2(7) << endl;	// 34

	std::function<int(int)> pow3 = std::bind(std::multiplies<int>(),
		std::bind(std::multiplies<int>(),
		std::placeholders::_1,
		std::placeholders::_1),
		std::placeholders::_1);
	cout << "x*x*x:		" << pow3(7) << endl;	// 343

	auto inversDivide = std::bind(std::divides<double>(),
		std::placeholders::_2,
		std::placeholders::_1);
	cout << "invdiv:	" << inversDivide(49, 7) << endl;	// 0.142857

	return 0;
}